home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / WN_PUTS.C < prev    next >
C/C++ Source or Header  |  1991-10-08  |  5KB  |  151 lines

  1. /*
  2. ** wn_puts - output string to window
  3. **
  4. ** Copyright (c) 1984, 1985, 1986 - Philip A. Mongelluzzo
  5. ** All rights reserved.
  6. **
  7. */
  8.  
  9. #include "winboss.h"
  10.  
  11. /*
  12. ***********
  13. * wn_puts *
  14. ***********
  15. */
  16.  
  17. wn_puts(wn, row, col, s)                /* put simple string */
  18. WINDOWPTR wn;
  19. int row,col;
  20. char *s;
  21. {
  22. int matrib;                             /* local attribute */
  23. char *p, *p1, *p2;                      /* local pointer */
  24. int l1,l2;                              /* length of s */
  25. int k;                                  /* scratch */
  26.                                         /* a few OBVIOUS checks */
  27.                                         /* don't allow writing on */
  28.                                         /* or beyond the border, if */
  29.                                         /* one exists */
  30.   matrib = wn->style;                   /* load attribute */
  31.   wns_fixc(&matrib);                    /* fixup */
  32.   k = wn->uly + row + WMR;
  33.   if(k > (wni_mxrows-1)) return(NULL);  /* dont be real stupid */
  34.   if( (k) >= (wn->uly + WMR + wn->ysize) && WMR) return(NULL);
  35.  
  36.   if(!wn_activate(wn)) return(NULL);    /* bring window to the top */
  37.   wns_err(wn, "wn_puts");               /* avoid disaster */
  38.   l1=strlen(s);                         /* length */
  39.   p = malloc((l1*2)+2);                 /* fetch some memory */
  40.   if(!p) return(NULL);                  /* error */
  41.  
  42.   while(l1+col > wn->xsize) l1--;       /* dont allow border overflow */
  43.   l2=l1;                                /* carbon copy for savres */
  44.   wn->ccy = row + WMR/2;                /* adjust virtual cursor */
  45.   wn->ccx = col + l1 + WMR/2;
  46.   p1 = p;                               /* set up pointers */
  47.   p2 = s;                               /* for both source & dest */
  48.   while (l1--) {                        /* build char,,atrib */
  49.     *p1++ = *p2++;                      /* pair */
  50.     *p1++ = (char)matrib;               /* for write */
  51.   }
  52.   *p1 = '\0';                           /* terminate string */
  53.   row = wn->uly + row + WMR/2;          /* adjust position */
  54.   col = wn->ulx + col + WMR/2;
  55.   wns_savres(wn->page, row, col, l2, row, p, RESTORE);
  56.   free(p);
  57.   if(wn->synflg)                        /* and position */
  58.     v_locate(wn->page, wn->uly+wn->ccy, wn->ulx+wn->ccx);
  59.   return(TRUE);
  60. }
  61.  
  62. /*
  63. ************
  64. * wn_putsa *
  65. ************
  66. */
  67.  
  68. wn_putsa(wn, row, col, s, atrib)        /* put simple string with atrib */
  69. WINDOWPTR wn;
  70. int row,col;
  71. char *s;
  72. unsigned atrib;
  73. {
  74. static int satrib;                      /* a place to save current atrib */
  75. int rv;                                 /* return value from wn_puts */
  76. int matrib;
  77.  
  78.   if(!wn_activate(wn)) return(NULL);    /* bring window to the top */
  79.   matrib = atrib;                       /* my copy */
  80.   wns_err(wn, "wn_putsa");              /* avoid disaster */
  81.   satrib = wn->style;                   /* save current atrib */
  82.   wns_fixc(&matrib);                    /* fixup */
  83.   wn->style = atrib;                    /* force new atrib */
  84.   rv = wn_puts(wn, row, col, s);        /* do it with wn_puts */
  85.   wn->style = satrib;                   /* restore atrib */
  86.   return(rv);
  87. }
  88.  
  89.  
  90. /*
  91. ***********
  92. * wn_putc *
  93. ***********
  94. */
  95.  
  96. wn_putc(wn, row, col, c)                /* put simple character */
  97. WINDOWPTR wn;                           /* the window */
  98. int row,col;                            /* location */
  99. char c;                                 /* the character */
  100. {
  101. char s[3];                              /* character string */
  102.  
  103.   if(!wn_activate(wn)) return(NULL);    /* bring window to the top */   
  104.   wns_err(wn, "wn_putc");               /* avoid disaster */
  105.   s[0] = c;                             /* load character */
  106.   s[1] = '\0';                          /* terminate string */
  107.   return(wn_puts(wn, row, col, s));     /* print the string */
  108. }
  109.  
  110. /*
  111. ************
  112. * wn_putca *
  113. ************
  114. */
  115.  
  116. wn_putca(wn, row, col, c, a)            /* put simple character & atrib */
  117. WINDOWPTR wn;                           /* the window */
  118. int row,col;                            /* location */
  119. char c;                                 /* the character */
  120. unsigned a;                             /* the attribute */
  121. {
  122. char s[3];                              /* character string */
  123.  
  124.   if(!wn_activate(wn)) return(NULL);    /* bring window to the top */   
  125.   wns_err(wn, "wn_putca");              /* avoid disaster */
  126.   s[0] = c;                             /* load character */
  127.   s[1] = '\0';                          /* terminate string */
  128.   return(wn_putsa(wn, row, col, s, a)); /* print the string & atrib */
  129. }
  130.  
  131. /*
  132. ************
  133. * wn_getca *
  134. ************
  135. */
  136.  
  137. unsigned int wn_getca(wn, row, col)
  138. WINDOWPTR wn;
  139. int row, col;
  140.  
  141. {
  142.   if(!wn_activate(wn)) return(NULL);    /* make sure window is on top */
  143.   wns_err(wn,"wn_locate");              /* avoid disaster */
  144.  
  145.   row = row + wn->uly+WMR/2;            /* set physical address */
  146.   col = col + wn->ulx+WMR/2;
  147.   return(_getca(wn->page,row,col));     /* return char & attribute */
  148. }
  149.  
  150. /* End */
  151.